// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#ifndef _STDAFX_H_
#define _STDAFX_H_

#define _USE_32BIT_TIME_T 1

#include <dlcom/cominc.h>
#include <log/ilogs.h>

#define Rule_log    "logs"
#define Rule_Tables "tables"
#define Rule_Table  "table"
#define Rule_Save   "save"
#define Rule_Op     "op"

#define Rule_Fields       "fields"
#define Rule_Fields_Name  "name"
#define Rule_Fields_Type  "type"
#define Rule_Fields_Size  "size"
#define Rule_Fields_Index "index"

#define FIELD_TYPE_STRING "string"
#define FIELD_TYPE_INT    "int"

#define FILED_TYPE_PRIMARYKEY "PRIMARY KEY"
#define FILED_SQL_LEN         2048

#define FILED_ID     "id"
#define FILED_S_TIME "stm"
#define FILED_L_TIME "ltm"

#define TABLE_OP_BASE    0
#define TABLE_OP_UPDATE  TABLE_OP_BASE + 1
#define TABLE_OP_INSERT  TABLE_OP_BASE + 2
#define TABLE_OP_REFRESH TABLE_OP_BASE + 3

class LogData
{
public:
    LogData(unsigned char* json, unsigned long size)
    {
        data = ALLOC_NEW unsigned char[size + 1]();
        if (data.m_p != NULL) {
            len = size;
            s_memcpy(data, json, size);
        }
    }
    ~LogData() { data.dispose(); }
    unsigned char* GetData() { return data.m_p; }
    unsigned long GetLen() { return len; }

private:
    UCharArrayPtr data;
    unsigned long len;
};

typedef LogData* LogDataPtr;

typedef list<LogDataPtr> TaskList;
typedef TaskList::iterator TaskListIterator;

typedef list<path_string> RuleList;
typedef RuleList::iterator RuleListIterator;

typedef map<string, ITableStruct*> MapTableStruct;
typedef MapTableStruct::iterator MapTableStructIterator;

typedef vector<FieldSturct> Table;

#define IsJsonString(x) (sjson_is_string(x) == sjson_true)
#define IsJsonNumber(x) (sjson_is_double(x) == sjson_true)
#define IsJsonArray(x)  (sjson_is_array(x) == sjson_true)
#define IsJsonObject(x) (sjson_is_obj(x) == sjson_true)

#endif
